var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.use(express.static('public'));
app.get('/', function(req, res){
    res.sendFile(__dirname + '/index.html');
});
var count = 0;

io.on('connection', function(socket){
    count++;
    // socket.broadcast.emit('hi');
    console.log('a user connected',count);
    // socket.on('disconnect', function(){
    //     console.log('user disconnected');
    // });
    socket.on('chat message',function(msg){
        console.log('message: ' + msg);
        io.emit('chat message', msg);

    })
});

http.listen(3000, function(){
    console.log('listening on *:3000');
});


